package com.oi.test01.hw.tiMu10;

import com.oi.test01.entity.Demo1;

import java.lang.reflect.Field;

/**
 * @author bin
 * @date 2025 - 03 -19
 **/
public class CreateSql {
    public static String createSql(Class<?> clazz) {

        StringBuffer sql = new StringBuffer("insert into ");
        String name = clazz.getSimpleName();
        sql.append(name + "(");
        Field[] fields= clazz.getDeclaredFields();
        for (Field field : fields) {
            sql.append(field.getName()).append(",");
        }
        sql.deleteCharAt(sql.length() - 1);
        sql.append(") values (");
        for (Field field : fields) {
            sql.append("?,");
        }
        sql.deleteCharAt(sql.length() - 1);
        sql.append(")");
        return sql.toString();
    }

    public static void main(String[] args) {
        Demo1 d =  new Demo1("张三", 18, "男");

        System.out.println(createSql(d.getClass()));
    }
}
